package com.hejia.alauda.persistence.mybatis;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import com.hejia.alauda.entity.DayInventory;
import com.hejia.alauda.persistence.BaseMapper;

public interface DayInventoryMapper extends BaseMapper<DayInventory> {

	/**
	 * 根据日期查询每天保有量
	 * 
	 * @param startdate
	 * @param enddate
	 * @return
	 */
	public List<Map<String, Object>> inventoryByDay(String startdate,
			String enddate);

	/**
	 * 查询是否已存在
	 * 
	 * @param nowdate
	 * @return
	 */
	public Integer selectInventory(String nowdate);

	/**
	 * 删除已存在的
	 * 
	 * @param nowdate
	 */
	public void deleteInventory(String nowdate);

	/**
	 * 查询某天的保有量
	 * 
	 * @param statdate
	 * @return
	 */
	@Select("select amount from `dayinventory` where str_to_date(statDate,'%Y-%m-%d')=#{0}")
	@ResultType(value = Double.class)
	public Double selectInventoryByDate(String statdate);

	/**
	 * 查询某天的销售量
	 * 
	 * @param statdate
	 * @return
	 */
	@Select("SELECT DATE_FORMAT (statDate,'%Y-%m-%d') as da,sale as am from `dayinventory` where str_to_date(statDate,'%Y-%m-%d')>=#{0} and #{1}>=str_to_date(statDate,'%Y-%m-%d') order by da")
	@ResultType(value = Map.class)
	public List<Map<String, Object>> selectSalesByDate(String startdate,
			String enddate);

}
